package com.corticon.dialogs.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
 * Dialog entity.
 * 
 * @author Lifan Yang
 */
@Entity
@Table(name = "q_dialoginstance")
public class Dialog extends AuditableEntity implements Serializable {

    private Long dialogId;
    private Questionnaire questionnaire;
    private QuestionInSet lastQuestionPage;
    private Date effectiveDate;
    private Date expirationDate;
    private String id;
    private Set<Response> responses = new HashSet<Response>();
    private Set<Quote> quotes = new HashSet<Quote>();
    private Boolean completed;
    private boolean nextPage;
    private String sessionId;

    public Dialog() {
    }

    // Property accessors
    @Id
    @SequenceGenerator(name = "q_dialoginstance_id_seq",
            sequenceName = "q_dialoginstance_id_seq",
            allocationSize = 1, initialValue = 1)
    // Set allocationSize and initialValue
    // to let sequence increment following DB.
    @GeneratedValue(strategy = GenerationType.AUTO, generator =
            "q_dialoginstance_id_seq")
    @Column(name = "q_dialoginstance_id",  nullable = false, columnDefinition = "integer")
    public Long getDialogId() {
        return this.dialogId;
    }

    public void setDialogId(Long dialogId) {
        this.dialogId = dialogId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dialogassoc_q_dialog_id_oid")
    public Questionnaire getQuestionnaire() {
        return this.questionnaire;
    }

    public void setQuestionnaire(Questionnaire questionnaire) {
        this.questionnaire = questionnaire;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "lastpgqassoc_q_pg_q_id_oid")
    public QuestionInSet getLastQuestionPage() {
        return this.lastQuestionPage;
    }

    public void setLastQuestionPage(QuestionInSet lastQuestionPage) {
        this.lastQuestionPage = lastQuestionPage;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "effectivedate", length = 19)
    public Date getEffectiveDate() {
        return this.effectiveDate;
    }

    public void setEffectiveDate(Date effectiveDate) {
        this.effectiveDate = effectiveDate;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "expirationdate", length = 19)
    public Date getExpirationDate() {
        return this.expirationDate;
    }

    public void setExpirationDate(Date expirationDate) {
        this.expirationDate = expirationDate;
    }

    @Column(name = "id", length = 256)
    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "dialog")
    public Set<Response> getResponses() {
        return this.responses;
    }

    public void setResponses(Set<Response> responses) {
        this.responses = responses;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "dialog")
    public Set<Quote> getQuotes() {
        return this.quotes;
    }

    public void setQuotes(Set<Quote> quotes) {
        this.quotes = quotes;
    }

    public Boolean getCompleted() {
        return completed;
    }

    public void setCompleted(Boolean completed) {
        this.completed = completed;
    }

    public boolean getNextPage() {
        return nextPage;
    }

    public void setNextPage(boolean nextPage) {
        this.nextPage = nextPage;
    }
    @Column(name = "sessionid", length = 256)
	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}
}